# 需求说明：
# 1. 获取验证码： http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify
# 2. 登录： http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login
# 3. 断言：status_code, status, msg
#
# 实现要求：
# 1. 按照功能模块组织测试类，一条测试用例对应一个测试方法
# 2. 添加断言：响应状态码/success/code/message
# 3. 封装测试套件批量执行用例
# 4. 生成测试报告

import requests

class Test_verificationCode_logIn:

    def test_loginSuccessful(self):
        global imageVerificationCode
        global session
        session = requests.session()
        imageVerificationCode = session.get(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        print(imageVerificationCode.text)
        url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        test_data = {
            "username": "13488888888",
            "password": "123456",
            "verify_code":"8888"
        }
        response = session.post(url=url, data=test_data)
        print(response.json())
        assert response.status_code == 200
        assert response.json().get("status")== 1
        assert response.json().get("msg") == "登陆成功"

    def test_verificationCode01(self):
        session = requests.session()
        imageVerificationCode = session.get(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        print(imageVerificationCode.text)
        url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        test_data = {
            "username": "13088882828",
            "password": "123456",
            "verify_code": "8888"
        }
        response = session.post(url=url, data=test_data)
        print(response.json())
        assert response.status_code == 200
        assert response.json().get("status")== -1
        assert response.json().get("msg") == "账号不存在!"

    def test_verificationCode02(self):
        global imageVerificationCode
        global session
        session = requests.session()
        imageVerificationCode = session.get(url="http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=verify")
        print(imageVerificationCode.text)
        url = "http://tpshop-test.itheima.net/index.php?m=Home&c=User&a=do_login"
        test_data = {
            "username": "13488888888",
            "password": "error",
            "verify_code":"8888"
        }
        response = session.post(url=url, data=test_data)
        print(response.json())
        assert response.status_code == 200
        assert response.json().get("status")== -2
        assert response.json().get("msg") == "密码错误!"